// 加载完时，body{opacity: 1}
document.addEventListener('DOMContentLoaded', function() {
    document.body.className = 'active';
})
// banner区域
sendAxios('https://pcapi-xiaotuxian-front.itheima.net/home/banner').then(data=>{
    const imgArray = data.result;
    const img = document.querySelectorAll('.iot_banner img');
    for (let i = 0 ; i < 5 ; i++){
        img[i].src = imgArray[i].imgUrl;
        img[i].id = imgArray[i].id;
    }
})

// 前台分类
sendAxios('https://pcapi-xiaotuxian-front.itheima.net/home/category/mutli').then(data=>{
    const Array = data.result;
    const img = document.querySelectorAll('.iot_nav img');
    const name = document.querySelectorAll('.iot_nav div');
    for (let i = 0 ; i < 10 ; i++){
        img[i].src = Array[i].icon;
        img[i].id = Array[i].id;
        name[i].innerHTML = Array[i].name;
    }
})

// 热门推荐
sendAxios('https://pcapi-xiaotuxian-front.itheima.net/home/hot/mutli').then(data=>{
    const Array = data.result;
    const img = document.querySelectorAll('.iot_hot img');
    const p = document.querySelectorAll('.iot_hot p');
    //热门推荐详情
    const a = document.querySelectorAll('.iot_hot a');
    a[0].addEventListener('click', function(event) { 
        event.preventDefault(); 
        sendInformation('/hot/preference')
    }); 
    a[1].addEventListener('click', function(event) { 
        event.preventDefault(); 
        sendInformation('/hot/inVogue')
    });     
    a[2].addEventListener('click', function(event) { 
        event.preventDefault(); 
        sendInformation('/hot/oneStop')
    });     
    a[3].addEventListener('click', function(event) { 
        event.preventDefault(); 
        sendInformation('/hot/new')
    }); 
    for (let i = 0 ; i < 4 ; i++){
        img[2*i].src = Array[i].pictures[0];
        img[2*i+1].src = Array[i].pictures[1];
        img[2*i].alt = Array[i].alt;
        img[2*i+1].alt = Array[i].alt;
        img[2*i].id = Array[i].id;
        img[2*i+1].id = Array[i].id;
    }
    for (let i = 0 ; i < 3 ; i++){
        p[2*i].innerHTML = Array[i].title;
    }
})


